package logic

import (
	"context"
	"hzjt-oam/rpc/sys/internal/svc"
	"hzjt-oam/rpc/sys/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSysDeptByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetSysDeptByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSysDeptByIdLogic {
	return &GetSysDeptByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetSysDeptByIdLogic) GetSysDeptById(in *pb.GetSysDeptByIdReq) (*pb.GetSysDeptByIdResp, error) {
	one, err := l.svcCtx.DeptModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}

	var sys_dept = &pb.SysDept{
		Name:           one.Name,
		CreateBy:       one.CreateBy,
		CreateTime:     one.CreateTime,
		LastUpdateBy:   one.LastUpdateBy,
		LastUpdateTime: one.LastUpdateTime,
		DelFlag:        one.DelFlag,
	}

	return &pb.GetSysDeptByIdResp{SysDept: sys_dept}, nil
}
